<?php
session_start();
include("../include/util.inc.php");

function getCategory()
{
    try {
        $PDO = getPDO();
        $sql = "SELECT DISTINCT category FROM question";
        if (isset($_SESSION['uid'])) {
            $tmpuid = $_SESSION['uid'];
            $sql = $sql . " WHERE (`property` = 0 or `property` = $tmpuid)";
        } else {
            $sql = $sql . " WHERE `property` = 0";
        }
        // echo $_SESSION['uid'];
        // echo $sql . PHP_EOL;
        $result = $PDO->query($sql);
        return $result;
    } catch (\PDOException $e) {
        throw new \PDOException($e->getMessage(), (int) $e->getCode());
    }
}

try {
    $category = getCategory();
    $res = $category->fetchAll(PDO::FETCH_BOTH);
    echo json_encode($res);
} catch (\PDOException $e) {
    echo $e->getMessage();
}


?>